from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, func, Enum
from sqlalchemy.orm import relationship
from app.core.database import Base
import enum
from app.core.logger import get_logger

logger = get_logger(service="conversation")

# 定义对话类型常量
class DialogueType:
    NORMAL = "chat"
    DEEP_THINKING = "analysis"
    WEB_SEARCH = "search"
    AGENT = "agent"
    
    @classmethod
    def get_display_name(cls, value):
        """获取对话类型的中文显示名称"""
        mapping = {
            "chat": "普通对话",
            "analysis": "深度思考",
            "search": "联网检索",
            "agent": "智能体"
        }
        return mapping.get(value, value)

class Conversation(Base):
    __tablename__ = "conversations"
    
    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"))
    title = Column(String(100), nullable=False)
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
    status = Column(String(20), default="ongoing")
    dialogue_type = Column(String(20), nullable=False, default=DialogueType.NORMAL)
    
    # 关系
    user = relationship("User", back_populates="conversations")
    messages = relationship("Message", back_populates="conversation", cascade="all, delete-orphan")